﻿using System;
using System.Windows.Forms;

namespace LuckStar
{
    public partial class PrizeControl : UserControl
    {
        private Prize pp ;
        private Lucky _luck;

        /// <summary>
        /// 解决闪动
        /// </summary>
        protected override CreateParams CreateParams
        {
            get
            {
                var parms = base.CreateParams;
                parms.Style &= ~0x02000000; // Turn off WS_CLIPCHILDREN 
                return parms;
            }
        }

        public PrizeControl(Lucky luck, Prize p)
        {
            InitializeComponent();
            this.DoubleBuffered = true;
            _luck = luck;
            if (p != null)
            {
                pp = p;
                name.Text = p.Name;
                pname.Text = p.PrizeName;
                count.Text = p.Count.ToString() + "个名额";
                if (System.IO.File.Exists(p.Image))
                {
                    pictureBox1.Load(p.Image);
                }
                if (p.WinnersList.Count >= p.Count)
                    btn_do.Text = "查看中奖名单";

            }//绑定显示

        }

        PrizeForm pf;
        private void btn_do_Click(object sender, EventArgs e)
        {
            pf =new  PrizeForm(_luck, pp.guid);
            pf.FormClosed += Pf_FormClosed;
            pf.ShowDialog();
        }

        private void Pf_FormClosed(object sender, FormClosedEventArgs e)
        {
            
            MainForm mf = (MainForm)this.TopLevelControl;
            mf.ShowLuckInfo(true);           
        }

        private void 编辑ToolStripMenuItem_Click(object sender, EventArgs e)
        {
           
            new PrizeEditForm((MainForm)this.TopLevelControl,pp).ShowDialog();
        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("您确定清除奖项【" + pp.Name + "】吗？", "清除奖项", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                MainForm mf = (MainForm)this.TopLevelControl;
                mf.DelPrize(pp.guid);
            }
        }

        private void 增加ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new PrizeEditForm((MainForm)this.TopLevelControl,null).ShowDialog();
        }

        private void 清除该奖项中间数据ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("您确定清除该奖项中奖纪录么？", "清除中奖纪录", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                _luck = LuckAction.ClearData(_luck, pp.guid);
                MessageBox.Show("清除成功！");
                ((MainForm)this.TopLevelControl).ShowLuckInfo(false);
              
            }


        }
    }
}
